package com.jly.controller;

import com.jly.exception.APIException;
import com.jly.service.AirPlaneService;
import com.jly.vos.GuidanceDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Liwenhao
 * @date 2022/3/23 15:34
 * @description
 */
@RestController
@RequestMapping("/airplane")
public class AirPlaneController {


    @Resource
    private AirPlaneService airplaneService;



    @GetMapping("/launch/{id}")
    public Object launchAirplane(@PathVariable Long id) {
        if (null == id) {
            throw new APIException(-1, "ID不能为空");
        }
        return airplaneService.tackOffAirplane(id);
    }

    @GetMapping("/land/{id}")
    public Object landAirplane(@PathVariable Long id) {
        if (null == id) {
            throw new APIException(-1, "ID不能为空");
        }
        return airplaneService.landAirplane(id);
    }

    @GetMapping("/changeSpeed")
    public Object changeAirplaneSpeed(Long id, Double speed) {
        if (null == id) {
            throw new APIException(-1, "ID不能为空");
        }
        if (null == speed) {
            throw new APIException(-1, "速度不能为空");
        }
        return airplaneService.changeAirplaneSpeed(id, speed);
    }

    @PostMapping("/attack")
    public Object attack(@RequestBody GuidanceDataVo request) {
        return airplaneService.attack(request);
    }

    @GetMapping("/survey/{id}")
    public Object survey(@PathVariable Long id) {
        if (null == id) {
            throw new APIException(-1, "ID不能为空");
        }
        return airplaneService.survey(id);
    }



}
